package camid.test.testobjects;

import java.io.Serializable;

import camid.distribution.lifecycle.LifecycleScope;
import camid.distribution.lifecycle.LocationScope;
import camid.distribution.lifecycle.ManagedObject;
import camid.util.testobjects.DelayUtil;

@ManagedObject( lifecycleScope = LifecycleScope.PER_REQUEST, locationScope = LocationScope.CLOUD )
public class DelayObject implements IDelayObject, Serializable
{
	/**
	 * 
	 */
	private static final long serialVersionUID = 4044301419855036227L;

	/* (non-Javadoc)
	 * @see camid.test.testobjects.IDelayObject#doDelay(java.lang.Long)
	 */
	public Long doDelay(Long delay)
	{
		delay = DelayUtil.gaussianDelay(delay);
		Long startTime = System.currentTimeMillis();
		Long endTime = System.currentTimeMillis();
		while(endTime - startTime < delay)
		{
			try 
			{
				Thread.sleep(100);
				endTime = System.currentTimeMillis();
			} 
			catch (InterruptedException e) 
			{
				e.printStackTrace();
			}
		}
		return delay;
	}	
}
